package com.ruoyi.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.BelongingCompany;
import com.ruoyi.contract.service.IBelongingCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同所属公司Controller
 * 
 * @author ruoyi
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/contract/BelongingCompany")
public class BelongingCompanyController extends BaseController
{
    @Autowired
    private IBelongingCompanyService belongingCompanyService;

    /**
     * 查询合同所属公司列表
     */
    @PreAuthorize("@ss.hasPermi('contract:BelongingCompany:list')")
    @GetMapping("/list")
    public TableDataInfo list(BelongingCompany belongingCompany)
    {
        startPage();
        List<BelongingCompany> list = belongingCompanyService.selectBelongingCompanyList(belongingCompany);
        return getDataTable(list);
    }

    /**
     * 导出合同所属公司列表
     */
    @PreAuthorize("@ss.hasPermi('contract:BelongingCompany:export')")
    @Log(title = "合同所属公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BelongingCompany belongingCompany)
    {
        List<BelongingCompany> list = belongingCompanyService.selectBelongingCompanyList(belongingCompany);
        ExcelUtil<BelongingCompany> util = new ExcelUtil<BelongingCompany>(BelongingCompany.class);
        util.exportExcel(response, list, "合同所属公司数据");
    }

    /**
     * 获取合同所属公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:BelongingCompany:query')")
    @GetMapping(value = "/{belongingCompanyId}")
    public AjaxResult getInfo(@PathVariable("belongingCompanyId") Long belongingCompanyId)
    {
        return success(belongingCompanyService.selectBelongingCompanyByBelongingCompanyId(belongingCompanyId));
    }

    /**
     * 新增合同所属公司
     */
    @PreAuthorize("@ss.hasPermi('contract:BelongingCompany:add')")
    @Log(title = "合同所属公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BelongingCompany belongingCompany)
    {
        return toAjax(belongingCompanyService.insertBelongingCompany(belongingCompany));
    }

    /**
     * 修改合同所属公司
     */
    @PreAuthorize("@ss.hasPermi('contract:BelongingCompany:edit')")
    @Log(title = "合同所属公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BelongingCompany belongingCompany)
    {
        return toAjax(belongingCompanyService.updateBelongingCompany(belongingCompany));
    }

    /**
     * 删除合同所属公司
     */
    @PreAuthorize("@ss.hasPermi('contract:BelongingCompany:remove')")
    @Log(title = "合同所属公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{belongingCompanyIds}")
    public AjaxResult remove(@PathVariable Long[] belongingCompanyIds)
    {
        return toAjax(belongingCompanyService.deleteBelongingCompanyByBelongingCompanyIds(belongingCompanyIds));
    }
}
